cmake_minimum_required(VERSION 3.15)
project(Wuzi_ui C)

set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)

# Set output directories
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

include(FetchContent)

# Fetch and configure SDL2
FetchContent_Declare(
        SDL
        GIT_REPOSITORY https://gh.wf521.top/https://github.com/libsdl-org/SDL.git
        GIT_TAG release-2.28.5 # Using a specific tag for stability
)
FetchContent_MakeAvailable(SDL)

# Fetch and configure GLEW
FetchContent_Declare(
        glew
        GIT_REPOSITORY https://gh.wf521.top/https://github.com/nigels-com/glew.git
        GIT_TAG glew-2.2.0
)
# With GLEW, we need to enable the C/C++ project in its CMakeLists
set(GLEW_PROJECT_flavour "cmake" CACHE STRING "GLEW project flavour")
FetchContent_MakeAvailable(glew)

# Nuklear header is included locally

add_executable(main main.c)

# On Windows, we need to set the subsystem to "WINDOWS" to avoid a console window
if(WIN32)
    set_target_properties(main PROPERTIES WIN32_EXECUTABLE ON)
endif()

# Include directories
target_include_directories(main PRIVATE
        ${CMAKE_CURRENT_SOURCE_DIR}
        ${sdl_SOURCE_DIR}/include
        ${glew_SOURCE_DIR}/include
)

# Link libraries
target_link_libraries(main PRIVATE
        SDL2::SDL2main
        SDL2::SDL2
        glew_s # static glew
)

# OpenGL library depends on the platform
if(WIN32)
    target_link_libraries(main PRIVATE opengl32)
elseif(APPLE)
    target_link_libraries(main PRIVATE "-framework OpenGL")
else()
    target_link_libraries(main PRIVATE GL)
endif()
